<template>
    <view class="content">
        <view class="item" v-for="(item, index) in list" :key="index">
            <view class="item-left">
                <view class="name">{{item.name}}</view>
                <!-- 性别 1男 2女 -->
                <view class="male" v-if="item.gender == 1">男</view>
                <view class="female" v-if="item.gender == 2">女</view>
            </view>
            <view class="btn" @click="$gTo(`/mine/pages/child-info/child-details?id=${item.id}`)">查看详情</view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
        
        <view class="footer" @click="$gTo(`/mine/pages/child-info/child-add`)">添加孩子资料</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
            };
        },
        onShow() {
            this.page = 1
            this.list = []
            this.status = 'loadmore'
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            // 获取列表
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('child_data', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
            	}).then(ret => {
            		if (ret.success == 1000) {
            			if (ret.detail && ret.detail.child && ret.detail.child.length > 0) {
            				this.list = this.list.concat(ret.detail.child);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    page{
        background-color: #f5f5f5;
    }
    .content{
        padding: 20rpx 20rpx 100px;
    }
    .item{
        background-color: #fff;
        border-radius: 15rpx;
        margin-bottom: 20rpx;
        padding: 35rpx 25rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .item-left{
        flex: 1;
        display: flex;
        justify-content: flex-start;
        align-items: center;
    }
    .name{
        max-width: 425rpx;
        font-size: 32rpx;
        font-weight: bold;
        padding-right: 20rpx;
    }
    .male{
        width: 34rpx;
        height: 34rpx;
        border-radius: 6rpx;
        font-size: 26rpx;
        text-align: center;
        line-height: 34rpx;
        color: #2d96fa;
        background-color: #edf6ff;
    }
    .female{
        width: 34rpx;
        height: 34rpx;
        border-radius: 6rpx;
        font-size: 26rpx;
        text-align: center;
        line-height: 34rpx;
        color: #ff5748;
        background-color: #ffeeed;
    }
    .btn{
        padding: 15rpx 23rpx;
        border-radius: 10rpx;
        font-size: 24rpx;
        color: #fff;
        background-color: #f29700;
        margin-left: 15rpx;
    }
    
    .footer{
        width: 100vw;
        height: 95rpx;
        font-size: 34rpx;
        color: #fff;
        text-align: center;
        line-height: 95rpx;
        background-color: #f29700;
        position: fixed;
        bottom: 0;
        left: 0;
    }

</style>
